﻿using System;
using System.Threading;

namespace Proxy
{
    class Printer : IPrintable
    {
        private string name;

        public Printer()
        {
            HeavyJob("Printerのインスタンスを生成中。");
        }

        public Printer(string name)
        {
            this.name = name;
            HeavyJob("Printerのインスタンス(" + name + ")を生成中。");
        }

        private void HeavyJob(string msg)
        {
            Console.Write(msg);

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    Thread.Sleep(1000);
                }
                catch (Exception e)
                {
                }

                Console.Write(".");
            }

            Console.WriteLine("完了。");
        }

        #region IPrintable メンバ

        public void SetPrinterName(string name)
        {
            this.name = name;
        }

        public string GetPrinterName()
        {
            return name;
        }

        public void Print(string str)
        {
            Console.WriteLine("=== " + name + " ===");
            Console.WriteLine(str);
        }

        #endregion
    }
}
